package com.project2.service;

import com.project2.bean.vo.StatCountVo;
import com.project2.bean.vo.StatInnerRowsVo;
import com.project2.mapper.MarketOrderGoodsMapper;
import com.project2.mapper.MarketOrderMapper;
import com.project2.mapper.MarketUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @Author: MH
 * @Date: 2022-08-12 22:00
 * @Description: 统计报表的业务逻辑的具体实现,StatInnerRowsVo对于各个方法来说有冗余的成员变量,
 *                所以三个统计业务都可以直接只使用一个对象来接收`
 */
@Service
public class StatServiceImpl implements StatService{
    @Autowired
    MarketOrderGoodsMapper marketOrderGoodsMapper;
    @Autowired
    MarketOrderMapper marketOrderMapper;
    @Autowired
    MarketUserMapper marketUserMapper;


    /**
     *@Description:商品统计的具体实现,将从数据库取出的数据直接封装在StatInnerRowsVo对象中
     *@Param:
     *@return:
     *@date: 2022/8/13
     *@Author: MH
     */
    @Override
    public StatCountVo goodsCount() {
        ArrayList<StatInnerRowsVo> goodsInnerRowsVoList = marketOrderGoodsMapper.goodsCount();
       String[] goodsColumns={"day","orders","products","amount"};
        StatCountVo statCountVo = new StatCountVo(goodsColumns,goodsInnerRowsVoList);
        return statCountVo;
    }


    /**
     *@Description:订单统计的具体实现,将从数据库取出的数据直接封装在StatInnerRowsVo对象中
     *@Param:
     *@return:
     *@date: 2022/8/13
     *@Author: MH
     */
    @Override
    public StatCountVo ordersCount() {
        ArrayList<StatInnerRowsVo> ordersInnerRowsVoList = marketOrderMapper.ordersCount();
        String[] goodsColumns={"day","orders","customers","amount","pcr"};
        StatCountVo statCountVo = new StatCountVo(goodsColumns, ordersInnerRowsVoList);
        return statCountVo;
    }

    /**
     *@Description:用户统计的具体实现,将从数据库取出的数据直接封装在StatInnerRowsVo对象中
     *@Param:
     *@return:
     *@date: 2022/8/13
     *@Author: MH
     */
    @Override
    public StatCountVo usersCount() {
        ArrayList<StatInnerRowsVo> usersInnerRowsVoList = marketUserMapper.countId();
        String[] goodsColumns={"day","users"};
        StatCountVo statCountVo = new StatCountVo(goodsColumns, usersInnerRowsVoList);
        return statCountVo;
    }
}
